package com.gzx.plugin.tjzy.modular.company.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.core.entity.CustomVo;
import com.gzx.plugin.tjzy.modular.company.entity.bo.GzxCompanyAddOrEditBo;
import com.gzx.plugin.tjzy.modular.company.entity.bo.GzxCompanyIdBo;
import com.gzx.plugin.tjzy.modular.company.entity.bo.GzxCompanyQueryBo;
import com.gzx.plugin.tjzy.modular.company.entity.vo.GzxCompanyVo;
import com.gzx.plugin.tjzy.modular.company.service.GzxCompanyService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

import java.util.List;

/**
 * 委托公司
 * 前端访问路由地址为:/tjzy/company
 *
 * @author LionLi
 * @date 2024-09-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/company")
public class GzxCompanyController {

    private final GzxCompanyService companyService;

    /**
     * 分页查询委托公司列表
     */
    //@SaCheckPermission("/tjzy/company/pageList")
    @PostMapping("/pageList")
    public CommonResult<Page<GzxCompanyVo>> pageList(@RequestBody GzxCompanyQueryBo companyQueryBo) {
        return CommonResult.data(companyService.pageList(companyQueryBo));
    }

    /**
     * 获取委托公司详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public CommonResult<GzxCompanyVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id) {
        return CommonResult.data(companyService.queryById(id));
    }

    /**
     * 查询委托公司列表
     */
    @GetMapping("/listAll")
    public CommonResult<List<CustomVo>> listAll(@RequestParam String val) {
        return CommonResult.data(companyService.listAll(val));
    }

    /**
     * 新增委托公司
     */
    @CommonLog("添加委托公司")
    @PostMapping("/add")
    public CommonResult<Void> add(@RequestBody GzxCompanyAddOrEditBo companyAddOrEditBo) {
        companyService.insert(companyAddOrEditBo);
        return CommonResult.ok();
    }

    /**
     * 修改委托公司
     */
    @CommonLog("修改委托公司")
    @PostMapping("/edit")
    public CommonResult<Void> edit(@RequestBody GzxCompanyAddOrEditBo companyAddOrEditBo) {
        companyService.update(companyAddOrEditBo);
        return CommonResult.ok();
    }

    /**
     * 删除委托公司
     *
     * @param companyIdBo 主键串
     */
    @CommonLog("删除委托公司")
    @PostMapping("/del")
    public CommonResult<Void> remove(@RequestBody GzxCompanyIdBo companyIdBo) {
        companyService.deleteWithValidByIds(companyIdBo);
        return CommonResult.ok();
    }
}
